#include <iostream>

using namespace std;
typedef long long LL;

int main()
{
	int q; cin >> q;
	while (q--)
	{
		LL l, r; cin >> l >> r;
		LL x = l + r, y = r - l + 1;
		LL ret;
		if (x % 2 == 0) ret = x / 2 % 9 * y % 9;
		else ret = y / 2 % 9 * x % 9;
		cout << ret << endl;
	}
	return 0;
}